import React from "react";
import { View, Image, Text } from "@tarojs/components";

import "./index.less";

const Item = ({ data, onClick }) => {
  if (data.type === "ad") {
    return (
      <View
        className="item item-ad"
        onClick={() => {
          onClick && onClick(data);
        }}
      >
        <image src={data.img} />
      </View>
    );
  }
  if (data.type === "good") {
    return (
      <View
        className="item item-good"
        onClick={() => {
          onClick && onClick(data);
        }}
      >
        <View className="item-img">
          <Image src={data.img} />
          <View className="item-cert"></View>
        </View>
        <View className="item-title">{data.title}</View>
        <View className="item-desc">{data.desc}</View>
        <View className="item-price-cont">
          {data.coinNum ? (
            <>
              <View className="item-coint"></View>
              <Text>{data.coinNum + "+"}</Text>
            </>
          ) : null}
          <Text className="money-unit">￥</Text>
          <Text>{data.price}</Text>
          <Text className="item-org-price">{"￥" + data.orgPrice}</Text>
        </View>
      </View>
    );
  }
  return null;
};

export default Item;
